package com.zyzd.general.module.recyclerview.layoutmanager;

import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.StaggeredGridLayoutManager;

import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.zyzd.general.entity.local.UserEntity;
import com.zyzd.retrofit.base.BaseRecyclerFragment;

import static android.support.v7.widget.StaggeredGridLayoutManager.VERTICAL;

/**
 * Created by lzy on 2018/5/18 0018.
 * description ${RecyclerView LayoutManager 案例}
 */
public class TestLayoutManagerFragment extends BaseRecyclerFragment<TestLayoutManagerContract.IPresenter, TestLayoutManagerAdapter, UserEntity> implements TestLayoutManagerContract.IView {
    @Override
    public TestLayoutManagerAdapter createAdapter() {
        return new TestLayoutManagerAdapter(getContext());
    }

    @Override
    public TestLayoutManagerPresenter createPresenter() {
        return new TestLayoutManagerPresenter();
    }

    public static Fragment getInstance() {
        return new TestLayoutManagerFragment();
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {
        super.onRefresh(refreshLayout);
        int viewType = mAdapter.changeViewType();
        switch (viewType) {
            case TestLayoutManagerAdapter.VIEW_TYPE_GRID:
                mRecyclerView.setLayoutManager(new GridLayoutManager(getContext(), 2));
                break;
            case TestLayoutManagerAdapter.VIEW_TYPE_STAGGERED_GRID:
                mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, VERTICAL));
                break;
            case TestLayoutManagerAdapter.VIEW_TYPE_LINEAR:
            default:
                mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
                break;
        }
    }
}
